package com.neu.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.neu.entity.DeptVo;
import com.neu.entity.UserRoleVo;
import com.neu.service.SchedulingService;
import com.neu.util.JsonResult;
import com.neu.util.ResultCode;

@CrossOrigin
@RestController
@RequestMapping("/his/scheduling")
public class SchedulingController {
	@Autowired
	private SchedulingService schedulingService;
//	获取所有课室列表
	@GetMapping("/get_sc")
		public JsonResult<List<DeptVo>> getDeptList() {
		List<DeptVo> deptbo = schedulingService.getDeptList();
			return new JsonResult<List<DeptVo>>(ResultCode.SUCCESS,deptbo);		
		}
//	获取指定科室可排班的医生列表
	@PostMapping("/get_userRole")
		public JsonResult<List<UserRoleVo>> getUserRole(@RequestBody String body) {
		JSONObject json =JSON.parseObject(body);
		int deptID = (int) json.get("deptID");
		List<UserRoleVo> UserRoleVo = schedulingService.getUserRole(deptID);
			return new JsonResult<List<UserRoleVo>>(ResultCode.SUCCESS,UserRoleVo);
		}
//	获取所有的医生排班的规则
	@GetMapping("/get_AllUserRole")
		public JsonResult<List<UserRoleVo>> getAllUserRole() {
		List<UserRoleVo> UserRoleVo = schedulingService.getAllUserRole();
		return new JsonResult<List<UserRoleVo>>(ResultCode.SUCCESS,UserRoleVo);				
	}
//	修改排班规则的方法
	@PostMapping("/updateRole")
		public JsonResult<Boolean> updateRole(@RequestBody String body) {
		UserRoleVo userRoleVo= JSON.parseObject(body,UserRoleVo.class);
		System.out.println(userRoleVo);
		Boolean cifo = schedulingService.updateRole(userRoleVo);
        return new JsonResult<Boolean>(ResultCode.SUCCESS,cifo);		
	}

		
}
